﻿using System;
using Sheeter.Library.Model;
using System.Collections.Generic;
using Db4objects.Db4o;
using Db4objects.Db4o.Ext;

namespace Sheeter.Library.Dal
{
    public class AntecedentesMacDal
    {
        public static bool Insert(AntecedenteInfo antecedenteInfo)
        {
            using (IObjectContainer db = Db4oEmbedded.OpenFile("AntecedentesMac.db"))
            {
                try
                {
                    db.Store(antecedenteInfo);
                    db.Commit();
                    return true;
                }
                catch (Db4oException)
                {
                    return false;
                }
            }
            
        }
        public static bool Delete(AntecedenteInfo antecedenteInfo)
        {
            using (IObjectContainer db = Db4oEmbedded.OpenFile("AntecedentesMac.db"))
            {
                try
                {
                    db.Delete(antecedenteInfo);
                    db.Commit();
                    return true;
                }
                catch (Db4oException)
                {
                    return false;
                }
            }
        }
        public static List<AntecedenteInfo> GetAll()
        {
            List<AntecedenteInfo> lista;
            using (IObjectContainer db = Db4oEmbedded.OpenFile("AntecedentesMac.db"))
            {
                lista = new List<AntecedenteInfo>(db.Query<AntecedenteInfo>());
            }
            return lista;
        }
    }
}
